def debug(s):
    print s;

class Command(object):
    def check_and_run(self, wepye, req):
        if req.PATH_INFO.endswith(self.__class__.__name__):
            self.run(wepye, req)
            return True;
        else:
            return False;
    def run (self, wepye, req):
        return True

class runScript(Command):
    def run(self, wepye, req):
        if len(wepye.multiplex.fds()):
            debug("Already running")
            return False
        debug("runScript goes ^_^")
        src = req.REQUEST["src"]
        fd = wepye.multiplex.create(src);
        return True


class stopScript(Command):
    def run(self, wepye, req):
        debug("stopScript goes")
        wepye.multiplex.stop()
        return True

class getOutput(Command):
    def run(self, wepye, req):
        debug("Try to dump output")
        wepye.multiplex.dumphtml(req)
        return True

# TODO
class saveScript(Command):
    def run(self, wepye, req):
        debug("Try to Save the script.")
        filename = req.REQUEST["filename"]
        return False

#TODO
class loadScript(Command):
    def run(self, wepye, req):
        debug("Try to load the script.")
        filename = req.REQUEST["filename"]
        return False

#TODO
class commitProject(Command):
    def run(self, wepye, req):
        debug("Try to commit the Project.")
        filename = req.REQUEST["filename"]
        return False

#TODO
class newProject(Command):
    def run(self, wepye, req):
        pass
